/*

  This class define the Router class.
  which can be used to register router functions on paths.
  the router(app) method will be used to register all functions to app.

*/

var allies = require("./allies.js");
var index_handlers = require("./index_handlers.js");

exports.Router = Router;

var index_handlers = require("./index_handlers.js");
var user_handlers  = require("./user_handlers.js");
var user_stats_helper = require("./user_stats_helper.js");

function Router(allies){
    
    this.allies = allies;

}

Router.prototype.route = function(app){
    
    //handers the base routes component in the file allies.js
    var temp;
    for(var i = 0,temp = allies["homepage"];i < allies["homepage"].length;++i){
	app.get(temp[i],user_stats_helper);
	app.get(temp[i],index_handlers.homepage_handler);
    }
    
    for(var i = 0,temp = allies["reg"];i < allies["reg"].length;++i){
	app.get(temp[i],index_handlers._checkNotLogin);
	app.get(temp[i],index_handlers.reg_handler);
	
	app.post(temp[i],index_handlers._checkNotLogin);
	app.post(temp[i],index_handlers._reg_handler);
    }

    for(var i = 0,temp = allies["login"];i < allies["login"].length;++i){
	
	app.get(temp[i],index_handlers._checkNotLogin);
	app.get(temp[i],index_handlers.login_handler);
	
	app.post(temp[i],index_handlers._checkNotLogin);
	app.post(temp[i],index_handlers._login_handler);
	
	
    }

    for(var i = 0,temp = allies["logout"];i < allies["logout"].length;++i){
	app.get(temp[i],index_handlers._checkLogin);
	app.get(temp[i],index_handlers.logout_handler);
    }
    
    for(var i = 0,temp = allies["user"];i < allies["user"].length;++i){
	
	app.get(temp[i],index_handlers._checkLogin);
	app.get(temp[i],user_stats_helper);
	app.get(temp[i],user_handlers.setting_handler);

	app.post(temp[i],index_handlers._checkLogin);
	app.post(temp[i],user_handlers._setting_handler);
    }
    
    for(var i = 0,temp = allies["user_active"];
	i < temp.length;++i){
	app.get(temp[i],user_handlers.active_handler);
    }
}







